<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="utils.DBConnector"%>
<%@page import="utils.Printer"%>
<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255" />
<link href="style.css" rel="stylesheet" type="text/css" />
<title>Manage Courses</title>
<script type="text/javascript" src="showForm.js"> </script>
<script type="text/javascript" src="common_scripts.js"> </script>
</head>
<%	
if (request.getSession(false) == null || request.getSession(false).getAttribute("username") == null){
	response.sendError(HttpServletResponse.SC_FORBIDDEN, "Please login first");
	return;
}
		
if (!request.getSession(false).getAttribute("type").equals("admin")) {
	response.sendError(HttpServletResponse.SC_FORBIDDEN, "Only Admin can view this page");
	return;			
}
%>
		
<body onload = "setPage('manage_courses')">
<%@ include file="/WEB-INF/private/body_wrapper_header.html" %>


<%
boolean isEmpty;
DBConnector dbConn = new DBConnector();

PreparedStatement stmnt = dbConn.getConnection().prepareStatement(
			"SELECT c.course_name, credit_points, group_number, capacity, (SELECT COUNT(username) FROM user_courses WHERE course_name = c.course_name) AS registered, is_active " 	+  
			"FROM courses c ");

ResultSet res = stmnt.executeQuery();

isEmpty = !res.next(); //will be true if reultset is empty
res.beforeFirst();
%>

<h2> All courses: </h2>
<h4> Click on a course to add/remove seesions</h4>
<%
if (isEmpty){
	out.println("<h2> No courses exists in the system. </h2>");
}
else{
	Printer.printCoursesAdmin(out, res, "RemoveCourseFromDB", "course_details.jsp", "Remove Courses From System");	
}
	dbConn.close();
%>

<br />
<h3><a id="add_or_remove_course_button" href="#" onclick="showAddCourse('add_course_form.html')">Add new course</a></h3>

<span id="add_course"></span>

<%@ include file="/WEB-INF/private/body_wrapper_footer.html" %>
</body>
</html>